package com.example.service.impl;

import com.example.common.response.ServerResponse;
import com.example.dto.DemoDTO;
import com.example.dto.TypechoCommentsDTO;
import com.example.mapper.TypechoCommentsMapper;
import com.example.service.TypechoCommentsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @Auther: Swain
 * @Date: 2021/1/22 13:55
 * @Version 1.0.0
 */
@Log4j2
@Service
public class TypechoCommentsServiceImpl implements TypechoCommentsService {

    @Autowired
    private TypechoCommentsMapper typechoCommentsMapper;

    @Override
    public ServerResponse findListPage(TypechoCommentsDTO typechoCommentsDTO) {
        // 开启分页
        PageHelper.startPage(typechoCommentsDTO.getPageNum(), typechoCommentsDTO.getPageSize());
        // 执行查询
        List<TypechoCommentsDTO> dtoList = typechoCommentsMapper.findListByParams(typechoCommentsDTO);
        // 为空直接返回
        if (ObjectUtils.isEmpty(dtoList)) {
            return ServerResponse.createByNoData();
        }
        // 封装结果集
        PageInfo pageInfo = new PageInfo(dtoList);
        return ServerResponse.createBySuccess(pageInfo);
    }
}
